package com.peng.herostory;

import io.netty.channel.Channel;
import io.netty.channel.group.ChannelGroup;
import io.netty.channel.group.DefaultChannelGroup;
import io.netty.util.concurrent.GlobalEventExecutor;

public final class Broadcaster {
    private static final ChannelGroup channels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);

    private Broadcaster() {

    }

    /**
     * 广播消息
     *
     * @param msg
     */
    public static void broadcast(Object msg) {
        if (msg == null) {
            return;
        }
        channels.writeAndFlush(msg);
    }

    /**
     * 添加客户端
     *
     * @param channel
     */
    public static void addClient(Channel channel) {
        if (channel == null) {
            return;
        }
        channels.add(channel);
    }

    /**
     * 移除客户端
     *
     * @param channel
     */
    public static void removeClient(Channel channel) {
        channels.remove(channel);
    }


}
